package com.hc.controller;

import com.github.pagehelper.PageInfo;
import com.hc.Operation;
import com.hc.bean.SysMenuBean;
import com.hc.bean.SysRoleBean;
import com.hc.service.MenuSerivce;
import com.hc.util.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/SysMenuController")
@CrossOrigin
public class SysMenuController {


    @Autowired
    MenuSerivce menuSerivce;



    @GetMapping("/queryDataByLoginUserId")
    @Operation("查询登录用户权限")
    public JsonResponse queryDataByLoginUserId(Integer user_id){
        JsonResponse jsonResponse = new JsonResponse();
        try {
            List<SysMenuBean> menuBeanList =menuSerivce.queryDataByLoginUserId(user_id);
            jsonResponse.setCode(0);
            jsonResponse.setMsg("OK");
            jsonResponse.setData(menuBeanList);
        }catch (Exception e){
            e.printStackTrace();
            jsonResponse.setCode(1);
            jsonResponse.setMsg(e.getMessage());
        }
        return  jsonResponse;
    }

    @GetMapping("/queryMenuDataTree")
    @Operation("查询菜单树")
    public JsonResponse queryMenuDataTree(){
        JsonResponse jsonResponse = new JsonResponse();
        try {
            List<SysMenuBean> menuBeanList = menuSerivce.queryAllDataByTree();
             jsonResponse.setCode(0);
            jsonResponse.setMsg("OK");
            jsonResponse.setData(menuBeanList);
        }catch (Exception e){
            e.printStackTrace();
            jsonResponse.setCode(1);
            jsonResponse.setMsg(e.getMessage());
        }
        return  jsonResponse;
    }
}
